import {
  getRecommends,
  getShareSetting
} from '../../utils/service.js'
var config = require('../../config/config');
var enum_type = require('../../utils/enum');
var util = require('../../utils/util');
var common = require('../../utils/common');

Page({
  data: {
  },
  getShareInfo: function () {
    var that = this;
    var appId = config.appId;
    getShareSetting({
      appid: appId,
      "type": enum_type.pageEnum.FIND
    }).then(res => {
      that.setData({
        shareInfo: res
      })

    }).catch(e => {

    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getRecommends();
    this.getShareInfo();
    this.getNavlist();
  },
  getRecommends: function () {
    var that = this;
    var appId = config.appId;
    getRecommends({
      appid: appId
    }).then(res => {
      that.setData({
        recommends:res
      });

    }).catch(e => {

    })
  }, getNavlist: function () {

    let that = this;
    common.getNavlist(function (res) {
      var page = util.getCurrentPageUrl();
      for (var item in res) {

        if (res[item].pageUrl == page) {
          res[item].isSelect = true;
          break;
        }
      }
      that.setData({
        navs: res
      })
    });
  },jumpPage: function (event) {
    common.jumpPage(event);
  },
  onShareAppMessage: function (options) {

    var shareInfo = this.data.shareInfo;
    if (shareInfo) {
      return {
        title: shareInfo.title,
        imageUrl: shareInfo.imageSrc
      }
    }
  }
})